package org.example.route.controller.AdminController;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.route.model.dto.BaseRequest;
import org.example.route.model.dto.PriceDTO;
import org.example.route.model.dto.PriceQueryDTO;
import org.example.route.model.pojo.Result;
import org.example.route.model.vo.PriceVO;
import org.example.route.service.PriceService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor


@RestController
@RequestMapping("/admin/price")
@Slf4j
@Tag(name = "价格管理")
public class PriceController {
    @Autowired
    private PriceService priceService;

    //添加价格
    @Operation(summary = "添加价格")
    @PostMapping("/add")
    public Result add(@RequestBody PriceDTO priceDTO)
    {
        log.info("添加价格,{}",priceDTO);
           priceService.add(priceDTO);
           return Result.success();

    }

    //查找价格
    //TODO 比较复杂的逻辑
    //订票逻辑


    /** 测试完成，修改了GradeName错配的bug
    **/


    @Operation(summary = "查询价格")
    @PostMapping("/list")
    public Result<List<PriceVO>> list(@RequestBody PriceQueryDTO priceQueryDTO)
    {
           log.info("查询价格,{}",priceQueryDTO);
           List<PriceVO> priceVOS = priceService.list(priceQueryDTO);
           return Result.success(priceVOS);

    }





    //TODO 删除价格
    @Operation(summary = "删除价格")
    @PostMapping("/delete")
    public Result delete(@RequestBody BaseRequest baseRequest){
        log.info("删除价格,{}",baseRequest);
        priceService.delete(baseRequest);
        return Result.success();
    }


    @Operation(summary = "生成当前页面表格")
    @PostMapping("/generateTable")
    public void generateTable(@RequestBody PriceQueryDTO priceQueryDTO, HttpServletResponse response){
        log.info("生成当前页面表格,{}",priceQueryDTO);
        priceService.generateTable(priceQueryDTO,response);



    }

    @Operation(summary = "修改价格")
    @PostMapping("/update")
    public Result update(@RequestBody PriceDTO priceDTO){
        log.info("修改价格,{}",priceDTO);
        priceService.update(priceDTO);
        return Result.success();
    }






}
